package com.zimmur.app.mocolink.manage.web.util;

import javax.servlet.http.HttpServletRequest;

import com.zimmur.app.mocolink.domain.util.StringUtils;

public class FunctionUtils {
	/**
	 * 获取远程访问IP
	 * 
	 * @return
	 */
	public static String getRemoteIp(HttpServletRequest request) {
		String remoteIp = null;
		if (StringUtils.isBlank(remoteIp)) {
			remoteIp = request.getHeader("x-forwarded-for");
			if (StringUtils.isBlank(remoteIp) || "unknown".equalsIgnoreCase(remoteIp)) {
				remoteIp = request.getHeader("X-Real-IP");
			}
			if (StringUtils.isBlank(remoteIp) || "unknown".equalsIgnoreCase(remoteIp)) {
				remoteIp = request.getHeader("Proxy-Client-IP");
			}
			if (StringUtils.isBlank(remoteIp) || "unknown".equalsIgnoreCase(remoteIp)) {
				remoteIp = request.getHeader("WL-Proxy-Client-IP");
			}
			if (StringUtils.isBlank(remoteIp) || "unknown".equalsIgnoreCase(remoteIp)) {
				remoteIp = request.getHeader("HTTP_CLIENT_IP");
			}
			if (StringUtils.isBlank(remoteIp) || "unknown".equalsIgnoreCase(remoteIp)) {
				remoteIp = request.getHeader("HTTP_X_FORWARDED_FOR");
			}
			if (StringUtils.isBlank(remoteIp) || "unknown".equalsIgnoreCase(remoteIp)) {
				remoteIp = request.getRemoteAddr();
			}
			if (StringUtils.isBlank(remoteIp) || "unknown".equalsIgnoreCase(remoteIp)) {
				remoteIp = request.getRemoteHost();
			}
		}
		return remoteIp.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : remoteIp;
	}
}
